package com.ylc.chat.dao;

import com.ylc.chat.util.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author: ylc
 * @Description:好友列表持久层
 */
public class FriendsDao {
    /**
     * 根据用户名查询好友列表
     * @param uid
     * @return
     */
    public String getFriends(int uid){
        Connection conn = null;
        PreparedStatement pstmt =  null;
        ResultSet rs = null;
        String friends = "";
        try {
            conn =  JDBCUtil.getConnection();
            String sql = "select friends from friends where uid = ?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1,uid);
            rs = pstmt.executeQuery();
            while(rs.next()){
                friends = rs.getString("friends");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCUtil.close(rs,pstmt,conn);
        }
        return friends;
    }


}
